home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.teleport.com!usenet
- From: GHouck <hksys@teleport.com>
- Newsgroups: comp.lang.c++
- Subject: Re: File I/O using fwrite()
- Date: 18 Apr 1996 07:50:01 GMT
- Organization: systems hk
- Message-ID: <4l4s79$r1v@nadine.teleport.com>
- References: <31758D70.1D38@vixa.voyager.net>
- NNTP-Posting-Host: ip-pdx07-11.teleport.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
-
- David Wade <dwade@vixa.voyager.net> wrote:
- >HELP!!! I am having a major problem getting random access file routines
- >to work properly. For some reason, no matter what I do the information
- >is always written at the end of the file instead of where I want it to
- >replace... All I need to do is update a record in a potentailly large
- >file, and I can't load the entire file and re-write it to do it. If
- >anyone sees what I am doing wrong, or has a possible solution using
- >other means, I would greatly appreciate the info. The funtion looks
- >like this:
- > f=_fsopen(".\\data\\weapons.dat", "ab+", SH_DENYNONE);
- > if(f == NULL)
- > {
- [snip]
- > };
- > rewind(f);
- > fseek(f,(item_data.reference-1)*sizeof(item_struct),SEEK_SET);
- > fwrite(&item_data, sizeof(item_struct), 1, f);
- > fclose(f);
- >
- >
- >The struct is of type item_struct, and item_data is an instance of that
- >struct.
-
- If I were to hazard a guess, I'd say that since fseek wants a long
- type in the offset position, and your product probably does not
- result in a long value, it might be the problem. Why keep rewinding
- the file as well, since it probably results in extra i/o?
- If your variable (.reference) is not long, try:
-
- fseek(f,(long)(item_data.reference-1)*sizeof(item_struct),SEEK_SET);
-
- Yours, Geoff Houck
-
-